package com.shejimoshi.建造者模式;

import com.shejimoshi.建造者模式.common.Computer;
import com.shejimoshi.建造者模式.例子.ASUSComputerBuilder;
import com.shejimoshi.建造者模式.例子.Builder;
import com.shejimoshi.建造者模式.例子.ComputerDirector;
import com.shejimoshi.建造者模式.例子.DellComputerBuilder;

public class Test {
    public static void main(String[] args) {
        ComputerDirector director = new ComputerDirector();

        Builder asusBuilder = new ASUSComputerBuilder();
        Computer asusComputer = director.construct(asusBuilder);
        System.out.println(asusComputer.toString());

        Builder dellBuilder = new DellComputerBuilder();
        Computer dellComputer = director.construct(dellBuilder);
        System.out.println(dellComputer.toString());

        // 可以通过反射机制和配置文件配合，创建具体建造者对象
       /* ComputerDirector director = new ComputerDirector();

        // 从数据库或者配置文件中读取具体建造者类名
        Class c = Class.forName("com.designpattern.ASUSComputerBuilder");
        Builder asusBuilder = (Builder) c.newInstance();
        Computer asusComputer = director.construct(asusBuilder);
        System.out.println(asusComputer.toString());*/
    }
}
